<?
	require_once("includes/configuration.php");
	require_once("includes/common.php");
	define("MENU_HEIGHT",25);

  $CurrentMenuNumber = 0;

  $category = new CategoryBO();
  $category->parent = 0; 
$category->menuNumber = $CurrentMenuNumber;

  OB_START();
  $count = $category->getCount();
  OB_END_CLEAN();
// echo $category->last_query;

$SITE_LEFT_MENU_WIDTH = 170;

if (isset($MENU_SCRIPT))
	$MENU_SCRIPT.=<<<EOT
  var pos = "left";
  var ms = new mtDropDownSet(mtDropDown.direction.right, 0, 0, mtDropDown.reference.topRight);  
EOT;
else 
	$MENU_SCRIPT =<<<EOT
  var pos = "left";
  var ms = new mtDropDownSet(mtDropDown.direction.right, 0, 0, mtDropDown.reference.topRight);  
EOT;
?>
<script>function menuInit(){ mtDropDown.initialize(); }</script>

<?
function hasChilds($id)
{
   global $CurrentMenuNumber;
   $categories = new CategoryBO();
$categories->menuNumber = $CurrentMenuNumber;
   $categories->parent = $id;
   OB_START();
   $res = $categories->getCount()>0;
   OB_END_CLEAN();
   return $res;
}

function addMenu($id,$parent,$is_top,$item_n="") {
global $MENU_SCRIPT;
global $CurrentMenuNumber;
if($is_top)
{
$MENU_SCRIPT.=<<<EOT
  
  
  var m$id = $parent.addMenu(document.getElementById("m$id"));  
EOT;
}else
{
$pitem = $parent.".items[".$item_n."]";
$MENU_SCRIPT.=<<<EOT
  
  
  var m$id = $parent.addMenu($pitem);  
EOT;
}
    $categories = new CategoryBO();
$categories->menuNumber = $CurrentMenuNumber;
    $categories_lang = new CategoryLangBO();
    $categories_lang->langID = CURRENT_LANGUAGE_ID;
    $categories->leftJoin($categories_lang);
    $categories->parent = $id;
    $categories->visible = "1";
	OB_START();
    $categories->Load(0,0,array($categories->fields["position"] => "0"));
	OB_CLEAN();
    $item_n = 0;
    $has_url = false;
    while($categories->Next())
    {
      $has_url = ($categories->pageID>0 || strlen(trim($categories->caturl))>0) ? true : false;
      $URL="";
      if($has_url)
      {
        $URL=($categories->cattype=="0")?("/page.php?id=".$categories->pageID):(url_prepare_to_display($categories->caturl));
      } 
      $NAME = str_replace("'","/'",from_db($categories_lang->name));       
$MENU_SCRIPT.=<<<EOT
  
      m$id.addItem('$NAME','$URL');
EOT;
      if(hasChilds($categories->id))
      {
        addMenu($categories->id,"m".$id,false,$item_n);
      }
      $item_n++;
    }
}

$top_categories = new CategoryBO();

$top_categories->menuNumber = $CurrentMenuNumber;

$top_categories_lang = new CategoryLangBO();
$top_categories_lang->langID = CURRENT_LANGUAGE_ID;
$top_categories->leftJoin($top_categories_lang);
$top_categories->parent = "0";
$top_categories->visible = "1";
OB_START();
$top_categories->Load(0,0,array($top_categories->fields["position"] => "0"));
OB_CLEAN();
$has_childs = false;
$has_url = true;
while($top_categories->Next())
{
  $has_childs = hasChilds($top_categories->id);
  $has_url = ($top_categories->pageID>0 || strlen(trim($top_categories->caturl))>0) ? true : false;
  $URL="";
  if($has_url)
  {
    $URL=($top_categories->cattype=="0")?("page.php?id=".$top_categories->pageID):(url_prepare_to_display($top_categories->caturl));  
  } 
?>
<tr onmouseover="mover(this)" onmouseout="mout(this)">
 <td>
   <table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" id="m<?=$top_categories->id?>" name="m<?=$top_categories->id?>">
     <tr>
        <td width="10">&nbsp;</td>
              <td class="menu_left" onmouseover="mover(this)" onmouseout="mout(this)"
			   <? if($has_url){?>onClick="window.location.href='<?=$URL?>'"<?}?>><?=from_db($top_categories_lang->name)?></td>
        <td width=1><? if($has_childs){?><img width=7 height=7 hspace=2 src="images/menu/arrow.gif"/><?}?></td>
     </tr>
   </table>
 </td>
</tr>
<tr><td width="100%" bgcolor="#0067C6"><img width="100%" height=11 src="<?=SKIN_PATH?>images/menu-del.jpg"/></td></tr>
<?
  if($has_childs)
  {
    addMenu($top_categories->id,"ms",true);
  }    
}
$MENU_SCRIPT.=<<<EOT
  
  mtDropDown.renderAll();
EOT;

define('MENU_SCRIPT',$MENU_SCRIPT);
?>
